package com.example.dinghao.recyclerviewtest312dh.model;


import com.example.dinghao.recyclerviewtest312dh.bean.tcaseBean;
import com.example.dinghao.recyclerviewtest312dh.iface.tcaseListener;
import com.example.dinghao.recyclerviewtest312dh.iface.tcaseiface;
import com.example.dinghao.recyclerviewtest312dh.service.tcaseService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by dinghao on 2017/4/20.
 */
//获取文章数据
public class tcaseModel implements tcaseiface {
    private Retrofit retrofit;
    private String BASEURL="http://amicool.neusoft.edu.cn/";
    public tcaseModel()
    {
        retrofit = new Retrofit.Builder().baseUrl(BASEURL).addConverterFactory(GsonConverterFactory.create()).build();

    }
    @Override
    public void getResultList(String mod, int page, String SessionID, final tcaseListener tcaseListener) {
        tcaseService tcaseService =retrofit.create(tcaseService.class);
        Call<List<tcaseBean>> call= tcaseService.getResult(mod,page,SessionID);
        call.enqueue(new Callback<List<tcaseBean>>() {
            @Override
            public void onResponse(Call<List<tcaseBean>> call, Response<List<tcaseBean>> response) {
                if(response.isSuccessful()&& response.body()!=null)
                    tcaseListener.onResponse(response.body());
                else
                    tcaseListener.onFail("on response fail");
            }

            @Override
            public void onFailure(Call<List<tcaseBean>> call, Throwable t) {
                tcaseListener.onFail(t.toString());
            }
        });

    }

}
